//
//  UIBarButtonItem+Extension.swift
//  weibo_swift
//
//  Created by 紫荆秋雪 on 16/12/5.
//  Copyright © 2016年 紫荆秋雪. All rights reserved.
//

import UIKit

extension UIBarButtonItem {
    /**
     *  便利构造 UIBarButtonItem
     *  - title: 文字
     *  - fontSize: 字体大小
     *  - target: 监听对象
     *  - action: 监听方法
     *  - isBack: 是否带有返回箭头【true: 带有返回箭头，false: 默认没有返回箭头】
     */
    convenience init(title:String, fontSize:CGFloat = 16, target: Any?, action: Selector, isBack: Bool = false) {
        let btn: UIButton = UIButton(title: title, fontSize: fontSize, imageNormalName: nil, imageHighlightName: nil)
        
        let imageName = "navigationbar_back"
        if isBack {
            btn.setImage(UIImage(named:imageName), for: .normal)
            btn.setImage(UIImage(named:imageName + "_highlighted"), for: .highlighted)
        }
        btn.sizeToFit()
        // 添加点击事件
        btn.addTarget(target, action: action, for: .touchUpInside)
        self.init(customView: btn)
    }
}
